﻿using System;
using System.Diagnostics.Contracts;

namespace SessionHunter.Model
{
    /// <summary>
    /// Defines a single session from the database
    /// </summary>
    /// <remarks>Details can be found at http://msdn.microsoft.com/en-us/library/aa478952.aspx</remarks>
    [Serializable]
    public class SessionData
    {
        #region Variables
        private string _sessionId;
        private decimal _size;
        private Byte[] _data;
        private DateTime _created;
        private DateTime _expires;
        private DateTime _lockDate;
        private DateTime _lockDateLocal;
        private string _application;
        private int _timeOut;
        private bool _locked;
        #endregion

        /// <summary>
        /// Initializes a new instance of the <see cref="SessionData"/> class.
        /// </summary>
        /// <param name="sessionId">The session id.</param>
        /// <param name="size">The size of the whole session</param>
        public SessionData(string sessionId, decimal size)
        {
            Contract.Requires(!String.IsNullOrEmpty(sessionId), "Session ID cannot be null");

            _sessionId = sessionId;
            _size = size;
        }

        /// <summary>
        /// Gets or sets the session id.
        /// </summary>
        /// <value>Session ID + application ID</value>
        public string SessionId
        {
            get
            {
                return _sessionId;
            }
            set
            {
                _sessionId = value;
            }
        }

        /// <summary>
        /// Gets or sets the size of the session.
        /// </summary>
        /// <value>The size.</value>
        public decimal Size
        {
            get
            {
                return _size;
            }
            set
            {
                _size = value;
            }
        }

        /// <summary>
        /// Gets or sets the session data
        /// </summary>
        /// <value>Serialized session state</value>
        public Byte[] Data
        {
            get
            {
                return _data;
            }
            set
            {
                _data = value;
            }
        }

        /// <summary>
        /// Gets or sets the date/time the session was created
        /// </summary>
        /// <value>Date and time session was created (UTC)</value>
        public DateTime Created
        {
            get
            {
                return _created;
            }
            set
            {
                _created = value;
            }
        }

        /// <summary>
        /// Gets or sets the date/time the session will expire
        /// </summary>
        /// <value>Date and time session expires (UTC)</value>
        public DateTime Expires
        {
            get
            {
                return _expires;
            }
            set
            {
                _expires = value;
            }
        }

        /// <summary>
        /// Gets or sets the date/time the lock was created
        /// </summary>
        /// <value>UTC date and time session was locked</value>
        public DateTime LockDate
        {
            get
            {
                return _lockDate;
            }
            set
            {
                _lockDate = value;
            }
        }

        /// <summary>
        /// Gets or sets the date/time the local was created locally
        /// </summary>
        /// <value>Local date and time session was locked</value>
        public DateTime LockDateLocal
        {
            get
            {
                return _lockDateLocal;
            }
            set
            {
                _lockDateLocal = value;
            }
        }

        /// <summary>
        /// Gets or sets the time out for the session.
        /// </summary>
        /// <value>
        /// Session timeout in minutes
        /// </value>
        public int Timeout
        {
            get { return _timeOut; }
            set
            {
                _timeOut = value;
            }
        }

        /// <summary>
        /// Gets or sets the time out for the session.
        /// </summary>
        /// <value>
        /// 1=Session locked, 0=Session not locked
        /// </value>
        public bool Locked
        {
            get { return _locked; }
            set
            {
                _locked = value;
            }
        }

        /// <summary>
        /// Gets or sets the application.  This is either the path or the hexId
        /// </summary>
        /// <value>
        /// The application.
        /// </value>
        public string Application
        {
            get
            {
                return _application;
            }
            set
            {
                _application = value;
            }
        }
    }
}
